<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            color: #333;
            font-size: 16px;
        }
        
        a {
            color: #333;
            text-decoration: none;
        }
        
        table {
            box-sizing: border-box;
            width: 340px;
            /* height: 400px; */
            margin: 0 auto;
            padding: 20px;
            background: url(banner.jpg) no-repeat;
            background-size: 100% 100%;
        }
        
        input {
            outline: none;
            border: 1px solid grey;
            border-radius: 4px;
        }
        
        tr {
            display: inline-block;
            margin-bottom: 6px;
        }
        
        tr td:first-child {
            width: 80px;
        }
        
        table tr:nth-of-type(3) td {
            width: 200px;
        }
        
        .regist,
        button {
            box-sizing: border-box;
            display: inline-block;
            width: 50px;
            height: 30px;
            border: 1px solid #999;
            background-color: rgba(143, 188, 143);
            line-height: 30px;
            text-align: center;
            border-radius: 4px;
            margin-top: 8px;
            color: #333;
            opacity: 1;
            transition: all .5s;
            cursor: pointer;
            font-size: 16px;
        }
        
        .regist:hover,
        button:hover {
            opacity: 0.6;
            transform: scale(1.05);
            color: orange;
        }
        
        h2 {
            color: skyblue;
        }
        
        label {
            cursor: pointer;
        }
    </style>
</head>

<body>
    <table>
        <caption>
            <h2>用户登录</h2>
        </caption>
        <tbody>
            <tr>
                <td>
                    <label for="username">用户名:</label>
                </td>
                <td>
                    <input type="text" id="username">
                </td>
            </tr>
            <tr>
                <td>
                    <label for="password">密码:</label>
                </td>
                <td>
                    <input type="password" id="password">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="checkbox" id="autoLogin" style=" cursor: pointer;">
                    <label for="autoLogin" style="color: steelblue;">30天之内免登录</label>
                </td>
                <!-- <td></td> -->
            </tr>
            <tr class="last">
                <td>
                    <button id="login">登录</button>
                </td>
                <td>
                    <a href="register.html" class="regist">注册</a>
                </td>
            </tr>
        </tbody>

    </table>
</body>

</html>
<script src="jquery.min.js"></script>
<script>
    自动登录功能
    $(function() {
        let username = localStorage.getItem("username");
        let password = localStorage.getItem("password");
        if (password && username) {
            $("#username").val(username);
            $("#password").val(password);
            $("#login").click()
        }
    })
    $("#login").click(function() {
        let username = $("#username").val();
        let password = $("#password").val();
        if ((username && password)) {
            $.ajax({
                url: "http://10.35.164.246:8080/login",
                data: {
                    username: username,
                    password: password
                },
                success: function(data) {
                    if (data == "success") {
                        alert("聪明的小仙女！");
                        if ($("#autoLogin").prop("checked")) {
                            localStorage.setItem("username", username);
                            localStorage.setItem("password", password);
                        }
                        location.href = "http://10.35.164.246/registPage/toDoList.html";
                    } else {
                        alert("用户名或密码不正确")
                    }
                }
            })
        } else {
            alert("用户名或密码不能为空")
        }
    })
</script>